<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE>
<html>
<head>
<!-- 职业测评首页 -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../../css/top.css" />
<link rel="stylesheet" href="../../css/home.css" />
<script src="../../js/jquery.min.js"></script>

<title>智行校园-精准化服务平台</title>
</head>
<body class="background">
  <input type="hidden" value="职业测评"  />
  <div class="container">
      <h3>职业测试题</h3>
      <button class="test_float">1/26</button>
      <div class="test_container"></div>
      <button class="test_prev">
         <img src="../../img/prev.png"><span>上一题</span>
      </button>
      <button class="test_next">
         <span>下一题</span><img src="../../img/next.png"> 
      </button>
  </div>
  <form method="post"  name="userid_form" >
	    <input type="hidden" value="" name="userid" />
	    <input type="hidden" value="" name="type" />
	    <input type="hidden" value="" name="score" />
  </form>
  <script>
  		var user_id = '<%=session.getAttribute("userid")%>';
  		var user_name = '<%=session.getAttribute("username")%>';
  		var faceaddress = '<%=session.getAttribute("faceaddress")%>';
  		var faceaddress = '<%=session.getAttribute("faceaddress")%>';
  		var ticket = '<%=session.getAttribute("ticket")%>';
  		
	   $('body').append(' <input id="user_id" style="display:none" value="'+user_id+'"  />');
	   $('form[name="userid_form"] input[name="userid"]').attr('value',user_id);
 </script>
 <script src="../../js/top.js"></script>
 <script>
    $(function(){
      $.getJSON('/WDDXSERVER/professionalAssessment/getExamination',{userid:user_id,ticket:ticket},function(data){
    	  data = data[0].content.message;
    	  for(var i=0;i<data.length;i++){
  			$('div.test_container').append('<div  class="tests"></div>');
  			$('div.test_container div.tests:eq('+i+')').append('<h1>'+data[i].title+'</h1>');
				  for(var j=0;j<data[i].radio.length;j++){
					  $('div.test_container div.tests:eq('+i+')').append('<input type="radio"  name="radio'+i+'" id="radio'+i+j+'" value="'+data[i].radio[j].text+'" />');
					  $('div.test_container div.tests:eq('+i+')').append('<label for="radio'+i+j+'">'+data[i].radio[j].value+'</label>');
				  }
  		}
  		 var test_number=$('div.test_container div.tests').length-1;
  		  $('button.test_float').text('1/'+(test_number+1));
  		  var prev_count=0;
  		  var next_count=0;
  		  $('button.test_prev').click(function(){
  		      if(prev_count<=0)
  	    		  alert('已经是第一题')
  	    	  else{
  	    		  if(prev_count==test_number)
  	    			  $('button.test_next').find('span').text('下一题');
  	    	    $('div.test_container div:eq(0)').animate({'margin-left':'+=100%'});
  	    	    $('button.test_float').text(prev_count+'/'+(test_number+1));
  	    	    prev_count--;
  	    	  }
  			  next_count=prev_count;
  	      });
  	      $('button.test_next').click(function(){
  	    	 if(next_count==test_number){
  	    		 if($('div.test_container div:eq('+next_count+') input').is(":checked")){
  				  var P=0,J=0,E=0,I=0,S=0,N=0,T=0,F=0;
  				  $('div.test_container input').each(function(){
  					 if($(this).is(":checked")){
  						 switch($(this).attr('value')){
  						     case 'P':
  						          P++
  						          break;
  						     case 'J':
  						          J++
  						          break;
  						     case 'E':
  						          E++
  						          break;
  						     case 'I':
  						          I++
  						          break;
  						     case 'S':
  						          S++
  						          break;
  						     case 'N':
  						          N++
  						          break;
  						     case 'T':
  						          T++
  						          break;
  						     case 'F':
  						          F++
  						          break;
  						  }
  					  }
  				    });
  				  var conclusion= (I>=E ? 'I':'E')+( N>=S ? 'N':'S')+( F>=T ? 'F':'T')+(P >=J ? 'P':'J') ;
 				  var  score=[E,I,S,N,T,F,J,P];
 				 $('form[name="userid_form"] input[name="type"]').attr('value',conclusion);
 				 $('form[name="userid_form"] input[name="score"]').attr('value',score);
 				 $('form[name="userid_form"]').attr('action','test_conclusion.jsp');
 				 $('form[name="userid_form"]').submit();
  				  }
  	    		 else
  	    			alert("作答后查看测试结果");
  	    		 }
  	    	 
  	        else if($('div.test_container div:eq('+next_count+') input').is(":checked")){
  	    		  next_count++;
  	    		  if(next_count==test_number)
  	    			  $(this).find('span').text('查看测试结果');
  	    	      $('div.test_container div:eq(0)').animate({'margin-left':'-=100%'});
  	    	      $('button.test_float').text((next_count+1)+'/'+(test_number+1));
  	    	      }
  	        else
  	        	alert("作答后进入下一题！");
  	    	  prev_count=next_count;

  	      });
  	})
	 
     
  });
  
  </script>
</body>
</html>